package com.justnow.offer;

import java.util.HashSet;
import java.util.Scanner;

/**
 * @author justnow
 * Created on 2020-09-18
 * Description
 */
public class Ali02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int i = 0; i < T; i++) {
            int n = scanner.nextInt();
            int[] x = new int[n];
            int[] y = new int[n];
            for (int j = 0; j < n; j++) {
                x[j] = scanner.nextInt();
            }
            for (int j = 0; j < n; j++) {
                y[j] = scanner.nextInt();
            }

            System.out.println(big(x, y, n));
        }
    }

    public static int big(int[] x, int[] y, int n) {
        int sum = 0;
        HashSet<Integer> hashi = new HashSet<>();
        HashSet<Integer> hashj = new HashSet<>();
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if ((x[i] < x[j] && y[i] < y[j]) || (x[i] > x[j] && y[i] > y[j])) {
                    if (hashj.contains(j)) {
                        continue;
                    } else {
                        hashj.add(j);
                        sum++;
                    }

                }
            }
        }
        return sum;
    }
}
